require(['./config'], () => {
    require(['header', 'footer'], () => {
        class Login {
            constructor() {
                this.login_in()
            }
            login_in() {
                $("#login").on('click', function () {
                    var username = $('#username').val(),
                        password = $('#password').val()

                    var userlist = localStorage.getItem('userlist')
                    if (userlist) {
                        userlist = JSON.parse(userlist)
                        const issucc = userlist.some(userinfo => {
                            return userinfo.username === username && userinfo.password === password
                        })
                        if (issucc) {
                            util.setCookie('loginusername', username, { path: "/" })
                            alert("登录成功，即将跳转到首页！")
                            window.location.href = '/index.html'
                        } else {
                            alert("用户名或者密码错误，请重试！")
                        }
                    } else {
                        alert("该用户名未注册,请先注册！")
                        window.location.replace("./register.html")
                    }
                })
            }
        }
        return new Login()
    })
})